<?php
    class ArticleController extends Main_Controller_Action
    {
        private $_arrParam;
        private $_model;

        public function init()
        {
            $this->loadTemplates();
            $this->_arrParam = $this->_request->getParams();
            $this->_model = new Default_Model_Article();
            if(isset($this->_arrParam['lang'])) {
                $this->view->lang = $this->_arrParam['lang'];
            }
            else {
                $this->view->lang = 'vi';
            }
        }

        public function indexAction()
        {
            $this->view->headTitle('Julytour - Cảnh điểm nổi bật');
            $adapter = new Zend_Paginator_Adapter_DbSelect($this->_model->listItem($this->view->lang));
            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(12);
            $paginator->setPageRange(5);
            $currentPage = $this->_request->getParam('page', 1);
            $paginator->setCurrentPageNumber($currentPage);
            $this->view->data = $paginator;
        }

        public function detailsAction()
        {
            $id = (int) $this->_arrParam['id'];
            $this->view->data = $this->_model->getItem($id, $this->view->lang);
            $this->view->headTitle('Julytour - '.$this->view->data['title']);
            $data = array(
                'id' => $id,
                'location_id' => $this->view->data['location_id'],
            );
            $this->view->article = $this->_model->getItemByLocation($data, $this->view->lang);
        }

        public function locationAction()
        {
            $this->view->headTitle('Julytour - Cảnh điểm nổi bật');
            $location_id = (int) $this->_arrParam['id'];
            $adapter = new Zend_Paginator_Adapter_DbSelect($this->_model->getListItemByLocation($location_id, $this->view->lang));
            $paginator = new Zend_Paginator($adapter);
            $paginator->setItemCountPerPage(12);
            $paginator->setPageRange(5);
            $currentPage = $this->_request->getParam('page', 1);
            $paginator->setCurrentPageNumber($currentPage);
            $this->view->data = $paginator;
        }
    }
